import csv
import os


def load_login_data_from_csv(path):
    base_path = os.path.dirname(os.path.dirname(__file__))  # 获取项目根路径
    csv_path = os.path.join(base_path, path)
    result = []
    with open(csv_path, encoding='utf-8') as f:
        reader = csv.DictReader(f)
        for row in reader:
            # 字符串转布尔
            is_success = row['is_success'].strip().lower() == "true"
            result.append((row['mobile'], row['code'], is_success))
    return result

def load_article_status_data_from_csv(path):
    base_path = os.path.dirname(os.path.dirname(__file__))  # 获取项目根路径
    csv_path = os.path.join(base_path, path)
    result = []
    with open(csv_path, encoding='utf-8') as f:
        reader = csv.DictReader(f)
        for row in reader:
            result.append((row['status'], row['tag'], row['code']))
    return result

def load_article_search_data_from_csv(path):
    base_path = os.path.dirname(os.path.dirname(__file__))  # 获取项目根路径
    csv_path = os.path.join(base_path, path)
    result = []
    with open(csv_path, encoding='utf-8-sig') as f:
        reader = csv.DictReader(f)
        for row in reader:
            result.append((row['state'], row['code'], row['keyword'],row['channel']))
    return result

def load_submitnews_case_data_from_csv(path):
    base_path = os.path.dirname(os.path.dirname(__file__))  # 获取项目根路径
    csv_path = os.path.join(base_path, path)
    result = []
    with open(csv_path, encoding='utf-8') as f:
        reader = csv.DictReader(f)
        for row in reader:
            result.append((row['标题'], row['内容'], row['图片'],row['标签'],row['频道'],row['封面'],row['is_success'].strip().lower() == 'true'))
    return result




# print(load_login_data_from_csv("data/login_data.csv"))
# print(load_article_status_data_from_csv("data/article_status_data.csv"))
# print(load_article_search_data_from_csv("data/pairwise_search_cases.csv"))
# print(load_submitnews_case_data_from_csv("data/pairwise_submitnems_cases.csv"))